package com.stgy.lease.web.api.controller;

import com.stgy.lease.common.result.Result;
import com.stgy.lease.common.utils.JwtUtil;
import com.stgy.lease.model.domain.LeaseAgreement;
import com.stgy.lease.web.api.service.LeaseAgreementService;
import com.stgy.lease.web.api.vo.AgreementDetailVo;
import com.stgy.lease.web.api.vo.AgreementItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:AgreementController
 * Package:com.stgy.lease.web.api.controller
 * Description:
 *
 * @Author:helei
 * @Create:2024/9/7 - 16:51
 */
@RestController
@RequestMapping("/app/agreement")
@Tag(name = "用户租约信息")
public class AgreementController {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    //http://localhost:8888/app/agreement/listItem GET
    @Operation(summary = "获取个人租约基本信息列表")
    @GetMapping("/listItem")
    public Result<List<AgreementItemVo>> listItem(@RequestHeader("access_token") String token,
                                                  HttpServletRequest request) {
        return Result.ok(leaseAgreementService.listItem(token,request));
    }

    //http://localhost:8888/app/agreement/getDetailById?id=1 GET
    @Operation(summary = "根据id获取租约详细信息")
    @GetMapping("/getDetailById")
    public Result<AgreementDetailVo> getDetailById(@RequestParam Long id) {
        return Result.ok(leaseAgreementService.getDetailById(id));
    }

    //http://localhost:8888/app/agreement/saveOrUpdate POST
    @Operation(summary = "保存或更新租约")
    @PostMapping("/saveOrUpdate")
    public Result<String> saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement){
        return Result.build(leaseAgreementService.saveOrUpdate(leaseAgreement));
    }

}
